<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SECTION</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../edit68k.css" rel="stylesheet" type="text/css">
<style>
<!--
td { font-family: Verdana, Arial, Helvetica, sans-serif }
.bodyline	{ background-color: #FFFFFF; border: 1px #98AAB1 solid; }

.forumline	{ background-color: #FFFFFF; border: 2px #006699 solid; }

td.row2	{ background-color: #D7E3D7; }
.code {
	font-family: Courier, 'Courier New', sans-serif; font-size: 11px; color: #006600;
	background-color: #FAFAFA; border: #D0E3DC; border-style: solid;
	border-left-width: 1px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px
}

-->
</style>
</head>

<body class="text">
<p class="heading">Assembler Directives - SECTION<hr noshade></p>
<p></p>
<p><b>SECTION</b> - This directive causes the program counter to be restored to the address 
following the last location allocated in the indicated section (or to zero if 
used for the first time). The ORG directive may be used within a section, at any 
time, to set the current program location. The assembler does not check for 
overlapping sections. The section directive provides a convenient way of 
separating code from data within a program.</p>

<p class="sourcecode">Usage:<br>
[label]&nbsp;SECTION [&lt;number&gt;]</p>

<blockquote>

<p>&lt;number&gt; must be in the range 0..15.&nbsp; No section numbers are 
reserved in any way. By default, the assembler will begin with section 0. Labels 
may be used for section numbers. If no section number is specified then a label 
is required and will be set to the value of the current section (0..15).<br>
&nbsp;</p>
</blockquote>
<p class="sourcecode">CODE&nbsp;&nbsp; 
EQU&nbsp;&nbsp;&nbsp; 0<br>
DATA&nbsp;&nbsp; 
EQU&nbsp;&nbsp;&nbsp; 1<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SECTION 
DATA<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ORG&nbsp;&nbsp;&nbsp;&nbsp; $2000<BR>
msg1&nbsp;&nbsp; DC.B&nbsp;&nbsp;&nbsp; 'Hello World',$d,$a,0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
SECTION CODE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ORG&nbsp;&nbsp;&nbsp;&nbsp; 
$1000<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;code&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
SECTION DATA<BR>
msg2&nbsp;&nbsp; DC.B&nbsp;&nbsp;&nbsp; 'EASy68K Rules!',$d,$a,0</p>

<p><br>
Macros may be written to change sections and restore the previous section as 
shown in the following example:</p>

<p class="sourcecode">DATA&nbsp; &nbsp; EQU&nbsp; &nbsp; &nbsp;0
<br>
CODE&nbsp; &nbsp; EQU&nbsp; &nbsp; &nbsp;1 <br>
<br>
MAC1&nbsp; &nbsp; MACRO <br>
SECT\@&nbsp; SECTION <br>
&nbsp; &nbsp; &nbsp; &nbsp; SECTION DATA <br>
&nbsp; &nbsp; &nbsp; &nbsp; DC.B&nbsp; &nbsp; 'Hello World.' <br>
&nbsp; &nbsp; &nbsp; &nbsp; SECTION SECT\@ <br>
&nbsp; &nbsp; &nbsp; &nbsp; ENDM </p>

<p><br>
It is also possible to write a macro that modifies its behavior using 
conditional assembly based upon the section it is in when invoked as shown in 
the following example:</p>
<p class="sourcecode">DATA&nbsp; &nbsp; EQU&nbsp; &nbsp; &nbsp;0
<br>
CODE&nbsp; &nbsp; EQU&nbsp; &nbsp; &nbsp;1 <br>
<br>
MAC2&nbsp; &nbsp; MACRO <br>
SECT\@&nbsp; SECTION <br>
&nbsp; &nbsp; &nbsp; &nbsp; IFEQ SECT\@-CODE <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOP <br>
&nbsp; &nbsp; &nbsp; &nbsp; ENDC <br>
&nbsp; &nbsp; &nbsp; &nbsp; IFEQ SECT\@-DATA <br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DC.B&nbsp; 'Greetings' <br>
&nbsp; &nbsp; &nbsp; &nbsp; ENDC <br>
&nbsp; &nbsp; &nbsp; &nbsp; ENDM</p>

<p>See <a href="macro.htm">Macro Assembly</a> for more help on 
writing macros.</p>
</body>
</html>